package com.leyou.search.controller;

import com.leyou.pojo.dto.SpuDto;
import com.leyou.search.entity.Goods;
import com.leyou.search.entity.Search;
import com.leyou.search.service.SearchService;
import com.leyou.search.service.impl.SearchServiceImpl;
import com.leyou.starter.elastic.dto.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class WebController {

    @Autowired
    private SearchService searchService;
    @Autowired
    private Demo demo;

    /**
     * 导入数据
     * @return
     */
    @GetMapping("/loadData")
    public ResponseEntity<String> loadData(){
       searchService.getData();
        return ResponseEntity.ok("ok");
    }

    /**
     * 自动补全
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public Mono<List<String>> autoCompletion(String key){
        Mono<List<String>> mono = searchService.autoCompletion(key);
//        System.out.println(demo.getA()+"---------");
        return mono;
    }

    /**
     * 条件搜索商品
     * @param search
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>>  searchGoodsByCondition(@RequestBody  Search search){
        Mono<PageInfo<Goods>>  mono = searchService.searchGoodsByCondition(search);
        return mono;
    }
}
